﻿using DroidLord.Core;
using DroidLord.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DroidLord.app.dy
{
    class DYDBManager
    {

        private static DYDBManager instance = null;

        static String mdbPath = null;
        string userinfoDir = null;
       
        public static DYDBManager  getInstance()
        {
            if(instance==null)
            {
                instance = new DYDBManager();
            }
            if (mdbPath== null)
            {
                mdbPath = PathManager.getAppDBPath(Common.DBBASE_DOUYIN);
            }
            return instance;
        }

        public string getUserInfoDir(string uid)
        {
            String userdir = mdbPath + "\\" + uid+"\\userinfo";
            if (!Directory.Exists(userdir))
            {
                Directory.CreateDirectory(userdir);
            }
            return userdir;
        }

        public string getUserGoodDir(string uid)
        {
            String userdir = mdbPath + "\\" + uid + "\\goodsinfo";
            if (!Directory.Exists(userdir))
            {
                Directory.CreateDirectory(userdir);
            }
            return userdir;
        }

        public Boolean  insertUserInfo(String uid,String userinfo)
        { 
            string userinfopath = getUserInfoDir(uid) + "\\userinfo.txt";
            return FileUtils.saveFile(userinfopath, userinfo);
        }
        public Boolean insertUserGoodInfo(String uid,string ymd,string cursor, String goodinfo)
        {
            string ymdDir = getUserGoodDir(uid) + "\\" + ymd;
            if (!Directory.Exists(ymdDir))
            {
                Directory.CreateDirectory(ymdDir);
            }
            string goodpath = ymdDir + "\\" + uid + "_"+cursor+"_" + MyUtils.getCurYMDHMS() + ".txt";
            return FileUtils.saveFile(goodpath,goodinfo);
        }
    }
}
